package loader_updater;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class UpdateInfoWindow extends JFrame{
	private static final long serialVersionUID = 1L;
	private Loader parentWindow;
	private JButton button;

public UpdateInfoWindow(Loader parent, int vNew, int v, String updatetext1, String updatetext2) {
		this.setTitle("Update-Info");
		this.setParentWindow(parent);
		JPanel panel = new ImagePanel("./src/ui/images/loader_logo_big.png");
		JPanel label = new JPanel();
		label.setLayout(new BoxLayout(label,BoxLayout.LINE_AXIS));
		JLabel label1 = new JLabel("Update-Info",JLabel.CENTER);
		label1.setFont(new Font("Dialog", Font.BOLD, 16));
		label.add(Box.createHorizontalGlue());
		label.add(label1);
		label.add(Box.createHorizontalGlue());
		label.setOpaque(false);
		label1.setForeground(Color.WHITE);
		label.setBorder(BorderFactory.createEmptyBorder(30, 10, 20, 10));
        label1.setHorizontalAlignment(JLabel.CENTER);
		panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS));
		
		JPanel labelBox = new JPanel();
		labelBox.add(label);
		label.setForeground(Color.WHITE);
		labelBox.setLayout(new BoxLayout(labelBox,BoxLayout.LINE_AXIS));		
		labelBox.setOpaque(false);
		ImageIcon icon = new ImageIcon("./src/ui/images/dialog_ok.png");
		button = new JButton("Fertig!",
				icon);
		button.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				UpdateInfoWindow.this.parentWindow.startMain();;
			}
		});
		
		button.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseEntered(java.awt.event.MouseEvent evt) {
				button.setBackground(Color.WHITE);
				button.setForeground(Color.BLACK);
			}

			public void mouseExited(java.awt.event.MouseEvent evt) {
				button.setBackground(Color.BLACK);
				button.setForeground(Color.WHITE);
			}
		});
		
		
		button.setMinimumSize(new Dimension(200,50));
		button.setPreferredSize(new Dimension(200,50));
		button.setMaximumSize(new Dimension(200,50));
		button.setBackground(Color.BLACK);
		button.setForeground(Color.WHITE);
		button.setFont(new Font("Dialog", Font.BOLD, 16));
		
		panel.setPreferredSize(new Dimension(800,366));
	
		
		JPanel infoPanel = new JPanel();
		JPanel infoPanelBox = new JPanel();
		
		infoPanelBox.setLayout(new GridLayout(1,1));
		infoPanel.setLayout(new BoxLayout(infoPanel,BoxLayout.PAGE_AXIS));
		infoPanel.add(label);
		JLabel voldtext = new JLabel("Alte Version: "+getVersion(v));
		JLabel vnewtext = new JLabel("Neue Version: "+getVersion(vNew));
		JLabel textline = new JLabel("Info zum Update:");
		JLabel text = new JLabel(updatetext1);
		JLabel text2 = new JLabel(updatetext2);
		
		infoPanel.add(voldtext);
		infoPanel.add(vnewtext);
		infoPanel.add(textline);
		infoPanel.add(text);
		infoPanel.add(text2);
		
		voldtext.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
		vnewtext.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
		textline.setBorder(BorderFactory.createEmptyBorder(20, 10, 0, 10));
		text.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
		text2.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
		
		
		JPanel buttonbox = new JPanel();
		buttonbox.setOpaque(false);
		buttonbox.setLayout(new BoxLayout(buttonbox,BoxLayout.LINE_AXIS));
		buttonbox.add(Box.createHorizontalGlue());
		buttonbox.add(button);
		buttonbox.add(Box.createHorizontalGlue());
		buttonbox.setBorder(BorderFactory.createEmptyBorder(10, 10, 40, 10));
		
		infoPanel.add(Box.createVerticalGlue());
		infoPanel.add(buttonbox);
		infoPanel.setOpaque(true);
		
		for (int i = 0; i < infoPanel.getComponentCount(); i++) {
			infoPanel.getComponent(i).setForeground(Color.WHITE);
			infoPanel.getComponent(i).setFont(new Font("Dialog", Font.BOLD, 14));			
		}
		text.setForeground(Color.YELLOW);
		text2.setForeground(Color.YELLOW);
		button.setFocusPainted(false);
		infoPanelBox.add(infoPanel);
		infoPanelBox.setPreferredSize(new Dimension(700,300));
		infoPanelBox.setOpaque(false);
		infoPanel.setOpaque(false);
		panel.add(infoPanelBox);
		this.add(panel);
		this.setUndecorated(true);
		pack();
		setLocationRelativeTo(parent);
		setVisible(true);	   
	}

private String getVersion(int v) {
	String result = ""+v;
	result=result.substring(0, 1)+"."+result.substring(1);
	return result;
}

public Loader getParentWindow() {
	return parentWindow;
}

public void setParentWindow(Loader parentWindow) {
	this.parentWindow = parentWindow;
}

}
